package com.lagou.rocketmq.consumer;

import com.lagou.rocketmq.dao.GoodsQuantityDao;
import com.lagou.rocketmq.dao.OrderDao;
import com.lagou.rocketmq.model.Orders;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName PayConsumer
 * @Description TODO
 * @Author xsq
 * @Date 2020/11/25 16:58
 **/
@Slf4j
@Component
@RocketMQMessageListener(topic = "pay_check", consumerGroup = "pay_group")
public class PayConsumer implements RocketMQListener<String> {

    @Autowired
    private OrderDao orderDao;

    @Autowired
    private GoodsQuantityDao goodsQuantityDao;

    @Override
    public void onMessage(String id) {
        // 模拟支付状态检查，如支付成功，修改订单状态，如未支付修改订单状态并增加库存
        //获取订单信息
        Orders orders = orderDao.getOrderByOrderId(id);
        if (orders != null && orders.getOrderStatus() == 0) {
            //订单支付超时
            orders.setOrderStatus(2);
            orderDao.save(orders);
            /* goodsQuantityDao.addQuantity();*/
        }

    }
}